package cc.magicjson.easy.batch.core;

import cc.magicjson.easy.batch.builder.BatchOperationBuilder;
import cc.magicjson.easy.batch.config.BatchSqlProvider;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * Batch processor main class
 * Uses builder pattern and strategy pattern for configurable batch operations
 */
@Component
@Slf4j
@Getter
public class BatchProcessor<T> {
    private final JdbcTemplate jdbcTemplate;
    private final TransactionTemplate transactionTemplate;
    private final BatchSqlProvider sqlProvider;

    @Value("${batch.default-size:1000}")
    private int defaultBatchSize;

    public BatchProcessor(JdbcTemplate jdbcTemplate, PlatformTransactionManager transactionManager, BatchSqlProvider sqlProvider) {
        this.jdbcTemplate = jdbcTemplate;
        this.transactionTemplate = new TransactionTemplate(transactionManager);
        this.sqlProvider = sqlProvider;
    }

    public BatchOperationBuilder<T> builder() {
        return new BatchOperationBuilder<>(this);
    }
}
